package com.dreamers.extend;

import com.dreamers.core.Global;
import com.dreamers.core.MonoBehaviour;
import com.dreamers.pathcore.Vector2;

import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;

public class Camera extends MonoBehaviour {
    public static int offsetX;
    public static int offsetY;

    private Vector2 cameraPosition;

    public Vector2 getCameraPosition() {
        cameraPosition = new Vector2(offsetX, offsetY);
        return cameraPosition;
    }

    @Override
    public void keyPressed(KeyEvent e) {
        cameraMoveWithHorizontalAndVertical(e);
        // System.out.println(toString());
    }

    private void cameraMoveWithHorizontalAndVertical(KeyEvent e) {
        if (e.getKeyChar() == 'a') {
            offsetX -= 10;
        }
        if (e.getKeyChar() == 'd') {
            offsetX += 10;
        }
        if (e.getKeyChar() == 'w') {
            offsetY -= 10;
        }

        if (e.getKeyChar() == 's') {
            offsetY += 10;
        }
    }

    @Override
    public String toString() {
        return offsetX + "-" + offsetY;
    }

    public static Vector2 CameraPositionToGameWorldPostion(MouseEvent event) {
        System.out.println("CameraPositionToGameWorldPostion");
        return new Vector2(event.getX() + offsetX, event.getY() + offsetY);
    }

    @Override
    public void mouseWheelMoved(MouseWheelEvent e) {

        Global.CELL_SIZE += e.getWheelRotation();
    }
}
